#pragma once

#include "hMapNode.h"

template <typename Key, typename Val>
hMap<Key, Val>::hMap()
{
	_root = new hMapNode<Key, Val>(this);
}

template <typename Key, typename Val>
hMap<Key, Val>::~hMap()
{
	delete _root;
}

template <typename Key, typename Val>
template<typename... Args>
bool hMap<Key, Val>::emplace(Key k, Args... args)
{
	auto pNode = _root->emplaceCallback(k, args...);
	if (!pNode)
		return false;

	return pNode->emplaceFixup();
}

template <typename Key, typename Val>
bool hMap<Key, Val>::erase(Key k)
{
	auto retPr = _root->eraseCallback(k);
	if (retPr.first)
		return retPr.first->eraseFixup();

	return false;
}

template <typename Key, typename Val>
hMapNode<Key, Val>* hMap<Key, Val>::findByRank(size_t r) 
{ 
	return _root->findByRankCallback(r); 
}

template <typename Key, typename Val>
std::ostream& hMap<Key, Val>::fillDebug(std::ostream& os) const
{
	return _root->fillDebugCallback(os);
}
